// 1.在执行完new,生成实例后
var hook = {
  args: [
    "name",
    "age",
  ],
  taps: [
  ],
  call: function (...args) {
    this.call = this._createCall('sync');//调用它的时候 ，它会动态创建call函数，重写this.call属性
    return this.call(...args);//执行新创建的call方法，
  },
  callAsync: function (...args) {
    this.callAsync = this._createCall('async');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.callAsync(...args);//执行新创建的call方法，
  },
  promise: function (...args) {
    this.promise = this._createCall('promise');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.promise(...args);//执行新创建的call方法，
  },
  interceptors: [
  ],
}
// 2.执行hook.tapPromise过程中生成的tapInfo
const tapInfo = {
  name: "1",
  type: "promise",
  fn: (name, age, callback) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        console.log(1, name, age);
        resolve();
      }, 1000);
    });
  },
}
// 3.执行hook.tapPromise结束后，此时实例为
hook = {
  args: [
    "name",
    "age",
  ],
  taps: [
    {
      name: "1",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(1, name, age);
            resolve();
          }, 1000);
        });
      },
    },
    {
      name: "2",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(2, name, age);
            resolve();
          }, 2000);
        });
        
      },
    },
    {
      name: "3",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(3, name, age);
            resolve();
          }, 3000);
        });
        
      },
    },
  ],
  call: function (...args) {
    this.call = this._createCall('sync');//调用它的时候 ，它会动态创建call函数，重写this.call属性
    return this.call(...args);//执行新创建的call方法，
  },
  callAsync: function (...args) {
    this.callAsync = this._createCall('async');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.callAsync(...args);//执行新创建的call方法，
  },
  promise: function (...args) {
    this.promise = this._createCall('promise');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.promise(...args);//执行新创建的call方法，
  },
  interceptors: [
  ],
}
// 4.执行hook.promise生成的hook实例为
hook = {
  args: [
    "name",
    "age",
  ],
  taps: [
    {
      name: "1",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(1, name, age);
            resolve();
          }, 1000);
        });
      },
    },
    {
      name: "2",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(2, name, age);
            resolve();
          }, 2000);
        });
        
      },
    },
    {
      name: "3",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(3, name, age);
            resolve();
          }, 3000);
        });
        
      },
    },
  ],
  call: function (...args) {
    this.call = this._createCall('sync');//调用它的时候 ，它会动态创建call函数，重写this.call属性
    return this.call(...args);//执行新创建的call方法，
  },
  callAsync: function (...args) {
    this.callAsync = this._createCall('async');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.callAsync(...args);//执行新创建的call方法，
  },
  promise: function (...args) {
    this.promise = this._createCall('promise');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.promise(...args);//执行新创建的call方法，
  },
  interceptors: [
  ],
  _x: [
    (name, age, callback) => {
      return new Promise((resolve) => {
        setTimeout(() => {
          console.log(1, name, age);
          resolve();
        }, 1000);
      });
    },
    (name, age, callback) => {
      return new Promise((resolve) => {
        setTimeout(() => {
          console.log(2, name, age);
          resolve();
        }, 2000);
      });
      
    },
    (name, age, callback) => {
      return new Promise((resolve) => {
        setTimeout(() => {
          console.log(3, name, age);
          resolve();
        }, 3000);
      });
      
    },
  ],
}
// 5.执行factory.create传入的参数options为
options = {
  taps: [
    {
      name: "1",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(1, name, age);
            resolve();
          }, 1000);
        });
      },
    },
    {
      name: "2",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(2, name, age);
            resolve();
          }, 2000);
        });
        
      },
    },
    {
      name: "3",
      type: "promise",
      fn: (name, age, callback) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            console.log(3, name, age);
            resolve();
          }, 3000);
        });
        
      },
    },
  ],
  args: [
    "name",
    "age",
  ],
  interceptors: [
  ],
  type: "promise",
}
// 6.生成函数，并且传入参数(...args)执行
(function anonymous(name, age) {
  var _x = this._x;
  return new Promise((function (_resolve, _reject) {
      var _counter = 3;
      var _done = (function () {
          _resolve();
      });
      var _fn0 = _x[0];
      var _promise0 = _fn0(name, age);
      _promise0.then((function () {
          if (--_counter === 0) _done();
      }));
      var _fn1 = _x[1];
      var _promise1 = _fn1(name, age);
      _promise1.then((function () {
          if (--_counter === 0) _done();
      }));
      var _fn2 = _x[2];
      var _promise2 = _fn2(name, age);
      _promise2.then((function () {
          if (--_counter === 0) _done();
      }));
  }));
})(...args)